package kr.pe.mkseo.data;

import java.math.BigDecimal;
import java.util.Calendar;

import kr.pe.mkseo.data.persistence.CsvDataField;

import com.google.common.base.Preconditions;

public class Record implements Comparable<Record> {
	@CsvDataField(Order=0)
	private Calendar date_;
	@CsvDataField(Order=1)
	private BigDecimal amount_;
	
	public Record() {
	}
	
	public Record(Calendar date, BigDecimal amount) {
		date_ = date;
		amount_ = amount;
	}
	
	public Calendar GetDate() {
		return date_;
	}
	
	public BigDecimal GetAmount() {
		return amount_;
	}

	/**
	 * Returns less than zero if this date is after the other. This lets the new
	 * record appear earlier.
	 */
	@Override
	public int compareTo(Record o) {
		return -1 * date_.compareTo(o.GetDate());
	}
	
	@Override
	public boolean equals(Object o) {
		Preconditions.checkNotNull(o);
		Record br = (Record) o;
		if (amount_.equals(br.GetAmount()) && date_.equals(br.GetDate())) {
			return true;
		} else {
			return false;
		}
	}
	
	@Override
	public int hashCode() {
		return date_.hashCode() + amount_.hashCode(); 
	}
}